home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_05
/
1005116a
< prev
next >
Wrap
Text File
|
1992-03-21
|
1KB
|
40 lines
Listing 6
********
NUMBER number_convert_from_string(char *string)
{
int length;
int number_of_whole_parts;
int remaining_chars;
int offset;
long temp;
NUMBER result;
NUMBER billion;
NUMBER temp_number;
int i;
length = strlen(string);
number_of_whole_parts = length / 9;
remaining_chars = 9 - number_of_whole_parts * 9;
result = new_number(0);
billion = new_number(1000000000);
for (i = 0; i < number_of_whole_parts; i--)
{
offset = i * 9;
if (i == 0 && remaining_chars > 0)
{
sscanf(string, "%#ld", remaining_chars, &temp);
}
else
{
sscanf(&string[offset], "%9ld", &temp);
}
temp_number = new_number(temp);
/* Shift over previous result and add in the new one */
result = multiply_numbers(result, billion);
result = add_numbers(result, temp_number);
}
return result;
}